package com.mingtu.jgspatrol.view.popupview;

import android.content.Context;
import android.view.View;

import androidx.annotation.NonNull;

import com.lxj.xpopup.core.BottomPopupView;
import com.mingtu.bio.activity.PostingActivity;
import com.mingtu.common.utils.IntentUtils;
import com.mingtu.jgspatrol.R;
import com.mingtu.jgspatrol.databinding.LayoutBottomPopupMapToolBinding;
import com.mingtu.ocr.activity.RecStep1Activity;

/**
 * @ClassName :
 * @Author : wkk
 * @Date : 2023-10-18 16:32:07
 * @Email : 1281573890@qq.com
 * @Eescription :
 */
public class BottomPopupTool extends BottomPopupView implements View.OnClickListener {
    private OnStatusListener onStatusListener = null;
    private LayoutBottomPopupMapToolBinding popupBinding;

    public BottomPopupTool(@NonNull Context context) {
        super(context);
    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.layout_bottom_popup_map_tool;
    }

    @Override
    protected void onCreate() {
        super.onCreate();
        popupBinding = LayoutBottomPopupMapToolBinding.bind(bottomPopupContainer.getChildAt(0));
        addClickListener(this, popupBinding.layoutTool1, popupBinding.layoutTool2);
    }

    @Override
    protected void onShow() {
        super.onShow();
    }

    @Override
    protected void onDismiss() {
        if (onStatusListener != null)
            onStatusListener.onDismiss();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        popupBinding = null;
    }


    public void setOnStatusListener(OnStatusListener onStatusListener) {
        this.onStatusListener = onStatusListener;
    }

    // 添加通用点击监听器方法
    private void addClickListener(OnClickListener listener, View... views) {
        for (View view : views) {
            if (view != null) {
                view.setOnClickListener(listener);
            }
        }
    }

    @Override
    public void onClick(View v) {
        dismiss();
        switch (v.getId()) {
            case R.id.layout_tool1:
                IntentUtils.getInstance().readyGo(getActivity(), RecStep1Activity.class);
                break;
            case R.id.layout_tool2:
                IntentUtils.getInstance().readyGo(getActivity(), PostingActivity.class);
                break;
        }
    }

    public static interface OnStatusListener {
        void onDismiss();

        void onShow();
    }
}
